package com.pethospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pethospital.common.Result;
import com.pethospital.entity.Department;
import com.pethospital.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    /**
     * 分页获取科室列表
     */
    @GetMapping("/list")
    public Result<Page<Department>> list(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        Page<Department> departmentPage = departmentService.page(page, size);
        return Result.success(departmentPage);
    }

    /**
     * 获取科室详情
     */
    @GetMapping("/{id}")
    public Result<Department> getById(@PathVariable Long id) {
        Department department = departmentService.getById(id);
        return Result.success(department);
    }

    /**
     * 添加科室（管理员操作）
     */
    @PostMapping
    public Result<Void> add(@RequestBody @Valid Department department, HttpServletRequest request) {
        // 这里可以添加管理员权限校验
        departmentService.add(department);
        return Result.success();
    }

    /**
     * 更新科室（管理员操作）
     */
    @PutMapping
    public Result<Void> update(@RequestBody @Valid Department department, HttpServletRequest request) {
        // 这里可以添加管理员权限校验
        departmentService.update(department);
        return Result.success();
    }

    /**
     * 删除科室（管理员操作）
     */
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id, HttpServletRequest request) {
        // 这里可以添加管理员权限校验
        departmentService.delete(id);
        return Result.success();
    }
} 